package com.zx.job.mapper;

import Job.Dto.JobDto;
import Job.Dto.SalaryDto;
import org.apache.ibatis.annotations.*;

import java.util.List;

//@Repository
@Mapper
public interface JobRepository  {
    @Select("select space from workSpace where id = #{id}")
    String getWorkSpaceById(int id);
    @Select("select * from jobs where id = #{id}")
    JobDto findById(int id);

    @Select("select * from jobs")
    List<JobDto> findAll();

    @Update("update jobs " +
            "set company_id = #{companyId}, " +
            "category_id = #{categoryId}, " +
            "city = #{city}, " +
            "salary_l = #{salaryL}, " +
            "salary_r = #{salaryR}, " +
            "degree = #{degree}, " +
            "title = #{title}, " +
            "duties = #{duties}, " +
            "requests = #{requests}, " +
            "priorities = #{priorities}, " +
            "start_time = #{startTime}, " +
            "end_time = #{endTime} " +
            "where id = #{id}")
    void UpdateJob(JobDto jobDto);

    @Select("select * from jobs where (#{categoryId} = 0 or category_id = #{categoryId}) " +
            "and (#{city} = '不限' or city = #{city}) " +
            "and NOT (salary_l > #{salaryR} OR salary_r < #{salaryL})" +
            "and (#{degree} = '不限' or degree = #{degree})")
    List<JobDto> findByCriteria(@Param("categoryId") Integer categoryId,
                                @Param("city") String city,
                                @Param("salaryL") Integer salaryL,
                                @Param("salaryR") Integer salaryR,
                                @Param("degree") String degree);

    @Select("select salary_l as salaryL, salary_r as salaryR from jobs")
    List<SalaryDto> findAllSalary();

    @Insert("INSERT INTO jobs (company_id, category_id, city, salary_l" +
            ", salary_r, degree, title, duties, requests, priorities, start_time, end_time) " +
            "VALUES (#{companyId}, #{categoryId}, #{city}, #{salaryL}, " +
            "#{salaryR}, #{degree}, #{title}, #{duties}, #{requests}, " +
            "#{priorities}, #{startTime}, #{endTime})")
    void addJob(JobDto jobDto);

    @Select("select * from jobs where company_id = #{companyId}")
    List<JobDto> findByCompanyId(Integer companyId);


    @Delete("delete from jobs where id = #{id}")
    void deleteJob(int id);
}
